package com.iphanta.community.remote.utils;

import com.iphanta.community.common.message.CommunityMessage;
import com.iphanta.community.common.message.MessageContent;
import com.iphanta.community.common.utils.JsonUtils;

import java.util.*;

/**
 * @author 墨声 E-mail: zehong.hongframe.huang@gmail.com
 * create time: 4/15/22 11:21 AM
 */
public class Base64URL {

    public static byte[] base64EncodeUrl(byte[] input) {
        byte[] base64 = Base64.getEncoder().encode(input);
        for (int i = 0; i < base64.length; ++i)
            switch (base64[i]) {
                case '+':
                    base64[i] = '*';
                    break;
                case '/':
                    base64[i] = '-';
                    break;
                case '=':
                    base64[i] = '_';
                    break;
                default:
                    break;
            }
        return base64;
    }

    public static void main(String[] args) {
        TLSSigAPIv2 sigAPIv2 = new TLSSigAPIv2(1400664495
                , "a201f130d3e13e5d4a6cf5eeef50ffa87f7328c45c2222ba1d950cef428117fb");
        System.out.println(sigAPIv2.genUserSig("administrator", 9999999));

        Random random = new Random();
        Map<String, Object> request = new HashMap<>();
        request.put("SyncOtherMachine", 2);
        //TODO From_Account To_Account
        request.put("From_Account", "From_Account");
        request.put("To_Account", "To_Account");
        request.put("MsgSeq", 100000);
        request.put("MsgRandom", random.nextInt(1000000));
        request.put("MsgTimeStamp", System.currentTimeMillis()/1000L);

        Map<String, Object> body = new HashMap<>();
        body.put("MsgType", "TIMTextElem");

        Map<String, Object> MsgContent = new HashMap<>();

        CommunityMessage message = new CommunityMessage();
        {
            message.setType(10);
            message.setMessageSeq(100000L);
            MessageContent content = new MessageContent();
            content.setText("hosuhdoauhsoaushfdoausfhoauhsf");
            message.setContent(content);
        }

        MsgContent.put("Text", JsonUtils.INSTANCE.toJsonString(message));
        body.put("MsgContent", MsgContent);
        List<Object> msgBody = new ArrayList<>();
        msgBody.add(body);
        request.put("MsgBody", msgBody);

        System.out.println(JsonUtils.INSTANCE.toJsonString(request));
    }

}
